package com.wuhan.template.module.home.adapter;

import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.wuhan.template.R;
import com.wuhan.template.base.BaseApplication;
import com.wuhan.template.base.BaseViewHolder;
import com.wuhan.template.base.MyBaseAdapter;
import com.wuhan.template.module.find.webview.WebViewActivity;
import com.wuhan.template.module.home.entity.JiaoYuEntity;

import java.util.List;

import butterknife.BindView;

/**
 * Created by Administrator on 2016/5/11 0011.
 */
public class JiaoYuBaseAdapter extends MyBaseAdapter {

    private Context context;
    private ImageLoader loader;
    private DisplayImageOptions options;
    private List<JiaoYuEntity.ListBean> list;

    public JiaoYuBaseAdapter(Context context, List<JiaoYuEntity.ListBean> list) {
        super(context, list);
        this.context = context;
        this.list = list;
        loader = ((BaseApplication) (context.getApplicationContext())).getImageLoader();
        options = new DisplayImageOptions.Builder()
                .cacheOnDisk(true)
                .cacheOnDisk(true)
                .showImageOnFail(R.mipmap.app_logo)
                .build();
    }

    @Override
    public int getLayoutId() {
        return R.layout.home_jiaoyu_item;
    }

    @Override
    public BaseViewHolder getViewHolder() {
        ViewHolder holder = new ViewHolder();
        return holder;
    }

    @Override
    public void bindViews(View view, BaseViewHolder viewHolder) {
        ViewHolder holder = (ViewHolder) viewHolder;
        final JiaoYuEntity.ListBean listBean = list.get(holder.position);
        holder.title.setText(listBean.getTitle());
        holder.count.setText("评论数:  "+listBean.getChild_num());
        String imageUrl = listBean.getIndexpic().getHost() + listBean.getIndexpic().getDir() +
                listBean.getIndexpic().getFilepath() + listBean.getIndexpic().getFilename();
        loader.displayImage(imageUrl, holder.imageJiaoYu, options);

        view.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(context, WebViewActivity.class);
                intent.putExtra("url",listBean.getContent_url());
                intent.putExtra("title",listBean.getColumn_name());
                context.startActivity(intent);
            }
        });
    }

    public static class ViewHolder extends BaseViewHolder {

        @BindView(R.id.jiaoyu_itemTitle)
        TextView title;
        @BindView(R.id.jiaoyu_itemCount)
        TextView count;

        @BindView(R.id.jiaoyu_itemImage)
        ImageView imageJiaoYu;
    }
}
